package com.ztstkj.lzboard.adapters

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.PagerAdapter

class NotCivAdapter(val context:Context,val list:List<String>) : PagerAdapter(){

    override fun getCount(): Int {
       return list.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
       return view==`object`
    }

    /*
    override fun instantiateItem(container: ViewGroup, position: Int): Any {
    val iv = ImageView(context)
    iv.layoutParams= ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)
    Glide.with(context).load(list[position]).to(iv)
    container.addView(iv);
    return iv
    }
    */
    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        //Log.e("instantiateItem", "----------$position")
       val recycler=RecyclerView(context)
        val linearLayoutManager = LinearLayoutManager(context)
        linearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL

        recycler.layoutManager=linearLayoutManager
        recycler.adapter= HorizontalScrollItemAdapter(context,list)
        container.addView(recycler)
        return recycler
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as View?)
    }
}